package com.itheima.socket.tcp.demo11;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo11 {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9191);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("D:\\2019.7.30heima\\3.wmv"));
        byte[] bytes = new byte[1024];
        int length = -1;
        while ((length = inputStream.read(bytes)) != -1){
            bufferedOutputStream.write(bytes, 0, length);
        }

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("上传完成".getBytes());

        bufferedOutputStream.close();
//        inputStream.close();
        socket.close();
        serverSocket.close();
    }
}
